﻿namespace ReflectionStudio.LocalizationLibrary
{
    //.NET References
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    //LocalizationLibrary References
    using LocalizationLibrary.Messaging;

    /// <summary>
    /// Represent a description class for <see cref="DynamicResource"/>.
    /// </summary>
    public class DynamicResourceDescription
    {
        //Constructors

        /// <summary>
        /// Creates a new instance of <see cref="DynamicResourceDescription"/>.
        /// </summary>
        /// <param name="dynamicResource">Dynamic resource to wrap.</param>
        internal DynamicResourceDescription(DynamicResource dynamicResource)
        {
            if (dynamicResource == null)
            {
                throw new ArgumentNullException("dynamicResource parameter shouldn't be null.");                
            }
            this.DynamicResource = dynamicResource;
        }

        //Indexers

        /// <summary>
        /// Gets the text for the input language.
        /// </summary>
        /// <param name="language">Language.</param>
        /// <returns>The value for the input language.</returns>
        public Object this[Language language]
        {
            get
            {
                return this.DynamicResource[language];
            }
        }

        //Properties

        /// <summary>
        /// Gets/Sets the dynamic resource.
        /// </summary>
        private DynamicResource DynamicResource { get; set; }

        //Methods

        /// <summary>
        /// Gets the localized languages.
        /// </summary>
        /// <returns>localized languages.</returns>
        public Language[] GetLocalizedLanguages()
        {
            return this.DynamicResource.GetLocalizedLanguages();
        }

        /// <summary>
        /// Enforce localization for the input language.
        /// </summary>
        /// <param name="language">Language for localization.</param>
        public void EnforceLocalization(Language language) 
        {
            Language[] languages = this.DynamicResource.GetLocalizedLanguages();
            if ((language != null) && (!languages.Contains(language)))  
            {
                MessagingManager.Publish(new ResourceMessage(this.DynamicResource, Operation.Processed, language));
            }
        }
    }
}